package com.kaizeli.website.scheduler;

import com.kaizeli.website.service.WarningService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 预警定时任务调度器
 */
@Slf4j
@Component
@EnableScheduling
public class WarningScheduler {

    @Autowired
    private WarningService warningService;

    /**
     * 每天早上8点执行预警检查
     */
    @Scheduled(cron = "0 0 8 * * ?")
    public void dailyWarningCheck() {
        log.info("⏰ 触发每日预警检查任务（早上8点）");
        warningService.executeAllWarningChecks();
    }

    /**
     * 每2小时执行一次预警检查
     */
    @Scheduled(cron = "0 0 */2 * * ?")
    public void hourlyWarningCheck() {
        log.info("⏰ 触发每2小时预警检查任务");
        warningService.executeAllWarningChecks();
    }

    /**
     * 手动测试用：每分钟执行一次（开发测试时使用，生产环境请注释掉）
     */
    // @Scheduled(cron = "0 * * * * ?")
    // public void testWarningCheck() {
    //     log.info("⏰ 触发测试预警检查任务");
    //     warningService.executeAllWarningChecks();
    // }
}

